Fix build with imgui 1.92
authorTimo Röhling <roehling@debian.org>
Mon, 1 Sep 2025 14:51:26 +0000 (16:51 +0200)
committerTimo Röhling <roehling@debian.org>
Mon, 1 Sep 2025 15:23:06 +0000 (17:23 +0200)
Closes: #1112494
debian/patches/0023-Fix-build-with-imgui-1.92.patch [new file with mode: 0644]
debian/patches/series

diff --git a/debian/patches/0023-Fix-build-with-imgui-1.92.patch b/debian/patches/0023-Fix-build-with-imgui-1.92.patch
new file mode 100644 (file)
index 0000000..058f409
--- /dev/null
@@ -0,0 +1,142 @@
+From: =?utf-8?q?Timo_R=C3=B6hling?= <roehling@debian.org>
+Date: Mon, 1 Sep 2025 17:22:56 +0200
+Subject: Fix build with imgui 1.92
+
+---
+ libs/filagui/src/ImGuiHelper.cpp |  4 +-
+ libs/viewer/src/SimpleViewer.cpp | 83 +++++++++++++++++++++++++---------------
+ 2 files changed, 55 insertions(+), 32 deletions(-)
+
+diff --git a/libs/filagui/src/ImGuiHelper.cpp b/libs/filagui/src/ImGuiHelper.cpp
+index 91b2a4e..8b2d131 100644
+--- a/libs/filagui/src/ImGuiHelper.cpp
++++ b/libs/filagui/src/ImGuiHelper.cpp
+@@ -217,9 +217,9 @@ void ImGuiHelper::processImGuiCommands(ImDrawData* commands, const ImGuiIO& io)
+                 materialInstance->setScissor( pcmd.ClipRect.x, fbheight - pcmd.ClipRect.w,
+                         (uint16_t) (pcmd.ClipRect.z - pcmd.ClipRect.x),
+                         (uint16_t) (pcmd.ClipRect.w - pcmd.ClipRect.y));
+-                if (pcmd.TextureId) {
++                if (pcmd.GetTexID()) {
+                     TextureSampler sampler(MinFilter::LINEAR, MagFilter::LINEAR);
+-                    materialInstance->setParameter("albedo", (Texture const*)pcmd.TextureId, sampler);
++                    materialInstance->setParameter("albedo", (Texture const*)pcmd.GetTexID(), sampler);
+                 }
+                 rbuilder
+                         .geometry(primIndex, RenderableManager::PrimitiveType::TRIANGLES,
+diff --git a/libs/viewer/src/SimpleViewer.cpp b/libs/viewer/src/SimpleViewer.cpp
+index ec78013..2e774a6 100644
+--- a/libs/viewer/src/SimpleViewer.cpp
++++ b/libs/viewer/src/SimpleViewer.cpp
+@@ -94,6 +94,48 @@ static float getRangePlotValue(int series, void* data, int index) {
+     return ((float*) data)[series * 1024 + index];
+ }
++static ImGuiKey keyCodeToImGui(int keyCode)
++{
++    switch (keyCode) {
++        case 8:
++            return ImGuiKey_Backspace;
++        case 9:
++            return ImGuiKey_Tab;
++        case 13:
++            return ImGuiKey_Enter;
++        case 27:
++            return ImGuiKey_Escape;
++        case 35:
++            return ImGuiKey_End;
++        case 36:
++            return ImGuiKey_Home;
++        case 37:
++            return ImGuiKey_LeftArrow;
++        case 38:
++            return ImGuiKey_UpArrow;
++        case 39:
++            return ImGuiKey_RightArrow;
++        case 40:
++            return ImGuiKey_DownArrow;
++        case 46:
++            return ImGuiKey_Delete;
++        case 65:
++            return ImGuiKey_A;
++        case 67:
++            return ImGuiKey_C;
++        case 86:
++            return ImGuiKey_V;
++        case 88:
++            return ImGuiKey_X;
++        case 89:
++            return ImGuiKey_Y;
++        case 90:
++            return ImGuiKey_Z;
++        default:
++            return ImGuiKey_None;
++    }
++}
++
+ inline float3 curves(float3 v, float3 shadowGamma, float3 midPoint, float3 highlightScale) {
+     float3 d = 1.0f / (pow(midPoint, shadowGamma - 1.0f));
+     float3 dark = pow(v, shadowGamma) * d;
+@@ -426,26 +468,6 @@ void SimpleViewer::renderUserInterface(float timeStepInSeconds, View* guiView, f
+         auto& io = ImGui::GetIO();
+-        // The following table uses normal ANSI codes, which is consistent with the keyCode that
+-        // comes from a web "keydown" event.
+-        io.KeyMap[ImGuiKey_Tab] = 9;
+-        io.KeyMap[ImGuiKey_LeftArrow] = 37;
+-        io.KeyMap[ImGuiKey_RightArrow] = 39;
+-        io.KeyMap[ImGuiKey_UpArrow] = 38;
+-        io.KeyMap[ImGuiKey_DownArrow] = 40;
+-        io.KeyMap[ImGuiKey_Home] = 36;
+-        io.KeyMap[ImGuiKey_End] = 35;
+-        io.KeyMap[ImGuiKey_Delete] = 46;
+-        io.KeyMap[ImGuiKey_Backspace] = 8;
+-        io.KeyMap[ImGuiKey_Enter] = 13;
+-        io.KeyMap[ImGuiKey_Escape] = 27;
+-        io.KeyMap[ImGuiKey_A] = 65;
+-        io.KeyMap[ImGuiKey_C] = 67;
+-        io.KeyMap[ImGuiKey_V] = 86;
+-        io.KeyMap[ImGuiKey_X] = 88;
+-        io.KeyMap[ImGuiKey_Y] = 89;
+-        io.KeyMap[ImGuiKey_Z] = 90;
+-
+         // TODO: this is not the best way to handle high DPI in ImGui, but it is fine when using the
+         // proggy font. Users need to refresh their window when dragging between displays with
+         // different pixel ratios.
+@@ -465,25 +487,26 @@ void SimpleViewer::mouseEvent(float mouseX, float mouseY, bool mouseButton, floa
+         bool control) {
+     if (mImGuiHelper) {
+         ImGuiIO& io = ImGui::GetIO();
+-        io.MousePos.x = mouseX;
+-        io.MousePos.y = mouseY;
+-        io.MouseWheel += mouseWheelY;
+-        io.MouseDown[0] = mouseButton != 0;
+-        io.MouseDown[1] = false;
+-        io.MouseDown[2] = false;
++        io.AddMousePosEvent(mouseX, mouseY);
++        io.AddMouseWheelEvent(0, mouseWheelY);
++        io.AddMouseButtonEvent(0, mouseButton);
+         io.KeyCtrl = control;
+     }
+ }
+ void SimpleViewer::keyDownEvent(int keyCode) {
+-    if (mImGuiHelper && keyCode < IM_ARRAYSIZE(ImGui::GetIO().KeysDown)) {
+-        ImGui::GetIO().KeysDown[keyCode] = true;
++    if (mImGuiHelper) {
++        ImGuiKey key = keyCodeToImGui(keyCode);
++        if (key != ImGuiKey_None)
++            ImGui::GetIO().AddKeyEvent(key, true);
+     }
+ }
+ void SimpleViewer::keyUpEvent(int keyCode) {
+-    if (mImGuiHelper && keyCode < IM_ARRAYSIZE(ImGui::GetIO().KeysDown)) {
+-        ImGui::GetIO().KeysDown[keyCode] = false;
++    if (mImGuiHelper) {
++        ImGuiKey key = keyCodeToImGui(keyCode);
++        if (key != ImGuiKey_None)
++            ImGui::GetIO().AddKeyEvent(key, false);
+     }
+ }
index fd812d792d9b86b9a4b8e3ba571ac5cb35f1bf0d..0785b142dbac4431f58f9bb032e8e221b86e72f8 100644 (file)
@@ -20,3 +20,4 @@
 0020-Fix-shebang-to-use-Python-3.patch
 0021-Do-not-build-spirv-with-Werror.patch
 0022-Fixups-for-spirv.patch
+0023-Fix-build-with-imgui-1.92.patch